﻿@page "/list2"

<div class="d-flex">
    <div class="p-3" style="min-width: 200px;">
        <BootstrapInput TValue="string" placeholder="搜索" />
        <div class="mt-3" style="border: 1px solid #0094ff; border-radius: 3px; padding: 1rem; position: relative; overflow: auto;">
            <Tree Items="@CheckedItems" />
        </div>
    </div>
    <div class="p-3 flex-fill" style="max-width: calc(100% - 200px);">
        <div class="row mb-3">
            <div class="col-auto"><label class="col-form-label">用户ID：</label></div>
            <div class="col-auto"><BootstrapInput TValue="string" /></div>
            <div class="col-auto"><label class="col-form-label">用户名：</label></div>
            <div class="col-auto"><BootstrapInput TValue="string" /></div>
            <div class="col-auto"><label class="col-form-label">用户类型：</label></div>
            <div class="col-auto">
                <Select TValue="string">
                    <Options>
                        <SelectOption Text="类型1" Value="v1" />
                        <SelectOption Text="类型2" Value="v2" />
                        <SelectOption Text="类型3" Value="v3" />
                    </Options>
                </Select>
            </div>
        </div>
        <div class="mb-3">
            <Button Text="查询" />
            <Button Text="新增" />
            <Button Text="禁用" Color="Color.Danger" />
            <Button Text="角色配置" Color="Color.Info" />
        </div>
        <div class="mb-3">
            <div class="form-control" style="border: 1px solid #0094ff; border-radius: 3px;">数据信息</div>
        </div>
        <div class="mb-3">
            <Table TItem="TsbCode" ShowSkeleton="true"
                   IsPagination="true" PageItemsSource="@PageItemsSource"
                   IsStriped="true" IsBordered="true"
                   IsMultipleSelect="true" OnQueryAsync="@OnQueryAsync">
                <TableColumns>
                    <TableColumn @bind-Field="@context.CodeClass" Sortable="true" Text="编码" />
                    <TableColumn @bind-Field="@context.CodeName" Sortable="true" Text="名称" />
                    <TableColumn @bind-Field="@context.CodeSource" Sortable="true" Text="来源" />
                    <TableColumn @bind-Field="@context.CodeDesc1Name" Sortable="true" Text="描述1" Filterable="true" />
                    <TableColumn @bind-Field="@context.CodeDesc1Name" Sortable="true" Text="描述2" />
                    <TableColumn @bind-Field="@context.CodeDesc1Name" Sortable="true" Text="描述3" />
                    <TableColumn @bind-Field="@context.CodeDesc1Name" Sortable="true" Text="描述4" />
                </TableColumns>
            </Table>
        </div>
    </div>
</div>


@code {
    private IEnumerable<int> PageItemsSource => new int[] { 4, 8, 12, 20 };

    private List<TsbCode> TsbCodes { get; set; } = InitTsbCodes();

    private static List<TsbCode> InitTsbCodes() => Enumerable.Range(1, 80).Select(i => new TsbCode()
    {
        CodeClass = "CodeClass" + i,
        CodeName = "CodeName" + i,
        CodeSource = "CodeSource" + i,
        CodeDesc1Name = "CodeDesc1Name" + i,
        CodeDesc2Name = "CodeDesc2Name" + i,
        CodeDesc3Name = "CodeDesc3Name" + i,
        CodeDesc4Name = "CodeDesc4Name" + i,
    }).ToList();

    private Task<QueryData<TsbCode>> OnQueryAsync(QueryPageOptions options) => BindItemQueryAsync(TsbCodes, options);

    private Task<QueryData<TsbCode>> BindItemQueryAsync(IEnumerable<TsbCode> items, QueryPageOptions options)
    {
        var total = items.Count();
        items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

        return Task.FromResult(new QueryData<TsbCode>()
        {
            Items = items,
            TotalCount = total
        });
    }

    private IEnumerable<TreeItem> CheckedItems { get; set; } = GetCheckedItems();


    private static IEnumerable<TreeItem> GetCheckedItems()
    {
        var ret = new List<TreeItem>
        {
            new TreeItem() { Text = "导航一" },
            new TreeItem() { Text = "导航二", Checked = true, IsExpanded = true },
            new TreeItem() { Text = "导航三" }
        };

        ret[1].AddItem(new TreeItem() { Text = "子菜单一" });
        ret[1].AddItem(new TreeItem() { Text = "子菜单二", IsExpanded = true });
        ret[1].AddItem(new TreeItem() { Text = "子菜单三" });

        ret[1].Items.ElementAt(0).AddItem(new TreeItem() { Text = "孙菜单1一" });
        ret[1].Items.ElementAt(0).AddItem(new TreeItem() { Text = "孙菜单1二" });

        ret[1].Items.ElementAt(1).AddItem(new TreeItem() { Text = "孙菜单2一" });
        ret[1].Items.ElementAt(1).AddItem(new TreeItem() { Text = "孙菜单2二" });

        ret[1].Items.ElementAt(1).Items.ElementAt(1).AddItem(new TreeItem() { Text = "曾孙菜单一" });
        ret[1].Items.ElementAt(1).Items.ElementAt(1).AddItem(new TreeItem() { Text = "曾孙菜单二" });

        ret[1].Items.ElementAt(1).Items.ElementAt(1).Items.ElementAt(1).AddItem(new TreeItem() { Text = "曾曾孙菜单一" });
        ret[1].Items.ElementAt(1).Items.ElementAt(1).Items.ElementAt(1).AddItem(new TreeItem() { Text = "曾曾孙菜单二" });

        return ret;
    }
}
